package com.jiamao.goplay.ui.discover.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.jiamao.goplay.BR;
import com.jiamao.goplay.R;
import com.jiamao.goplay.data.DataRepository;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.tatarka.bindingcollectionadapter2.ItemBinding;
import me.tatarka.bindingcollectionadapter2.OnItemBind;

public class CityVM extends BaseViewModel<DataRepository> {


    public CityVM(@NonNull Application application, DataRepository repository) {
        super(application, repository);

        observableList.add(new CityMenuItemVM(this,"中国",true));
        observableList.add(new CityMenuItemVM(this,"亚洲",false));
        observableList.add(new CityMenuItemVM(this,"欧洲",false));
        observableList.add(new CityMenuItemVM(this,"北美洲",false));
        observableList.add(new CityMenuItemVM(this,"南美洲",false));
        observableList.add(new CityMenuItemVM(this,"大洋洲",false));
        observableList.add(new CityMenuItemVM(this,"非洲",false));

        uc.pSwitchEvent.setValue("中国");

    }

    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        //密码开关观察者
        public SingleLiveEvent<String> pSwitchEvent = new SingleLiveEvent<>();


        public SingleLiveEvent<String> setGrid = new SingleLiveEvent<>();
    }



    public interface OnItemClickListener {
        void onItemClick(String item);
    }

    OnItemClickListener listener = new OnItemClickListener() {
        @Override
        public void onItemClick(String item) {




        }
    };

    //给RecyclerView添加ObservableList
    public ObservableList<MultiItemViewModel> observableList = new ObservableArrayList<>();
    //RecyclerView多布局添加ItemBinding
    public ItemBinding<MultiItemViewModel> itemBinding = ItemBinding.of(new OnItemBind<MultiItemViewModel>() {
        @Override
        public void onItemBind(ItemBinding itemBinding, int position, MultiItemViewModel item) {
            //通过item的类型, 动态设置Item加载的布局
            String itemType = (String) item.getItemType();

            itemBinding.set(BR.viewModel, R.layout.discover_city_item_menu_layout);

        }
    });


    //给RecyclerView添加ObservableList
    public ObservableList<MultiItemViewModel> observableArrayList = new ObservableArrayList<>();
    //RecyclerView多布局添加ItemBinding
    public ItemBinding<MultiItemViewModel> itemBindingAddr = ItemBinding.of(new OnItemBind<MultiItemViewModel>() {
        @Override
        public void onItemBind(ItemBinding itemBinding, int position, MultiItemViewModel item) {
            //通过item的类型, 动态设置Item加载的布局

                itemBinding.set(BR.viewModel, R.layout.discover_city_item_layout);

        }
    });



    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
